<head th:include="certificateWeb/headFoot :: headerCss"></head>
<link href="/css/certificateWeb/login.css" rel="stylesheet">
<div th:include="certificateWeb/headFoot :: header"></div>
<body class="signin">
<div class="signinpanel">
	<div class="row">
		<div class="login_panel">
			<form id="signupForm">
				<h3 class="text-center">修改密码</h3>
				<!--<label>&nbsp;用户名：</label>&nbsp;&nbsp;-->
				<!--<label><input type="text" name="username" class="form-control reg_web" placeholder="用户名"/></label>-->
				<div class="box_1 pos" style="padding-left: 10px">
					<label class="label">&nbsp;手&nbsp;&nbsp;&nbsp;&nbsp;机&nbsp;&nbsp;&nbsp;&nbsp;号：</label>&nbsp;
					<label><input type="text" id="mobile" name="mobile" class="form-control reg_web" placeholder="手机号"/></label>
				</div>
				<div class="box_1 pos" style="padding-left: 10px">
					<label class="label">&nbsp;验&nbsp;&nbsp;&nbsp;&nbsp;证&nbsp;&nbsp;&nbsp;&nbsp;码：</label>&nbsp;
					<label><input type="text" id="code" name="code" class="form-control" style="width: 104px" placeholder="验证码"/></label>
					<label><input type="button" class="form-control" style="width: 96px; color: #555555 ;" onclick="send(this)" value="获取验证码" /></label>
				</div>
				<div class="box_1 pos" style="padding-left: 10px">
					<label class="label">&nbsp;新&nbsp;&nbsp;&nbsp;&nbsp;密&nbsp;&nbsp;&nbsp;&nbsp;码：</label>&nbsp;
					<label><input type="password" id="newPassWord" name="newPassWord" class="form-control reg_web" placeholder="新密码"/></label>
				</div>
				<div class="box_1 pos" style="padding-left: 10px">
					<label class="label">&nbsp;确认新密码：</label>&nbsp;
					<label><input type="password" id="password" name="password" class="form-control reg_web" placeholder="确认新密码"/></label>
				</div>
				<button class="btn btn-login btn-block" type="submit" style="margin: 20px auto;">确定</button>
			</form>
		</div>
	</div>
</div>
<div th:include="certificateWeb/headFoot :: footer"></div>
<script src="/js/plugins/layer/layer.min.js" th:src="@{/js/plugins/layer/layer.min.js}"></script>
<script src="/js/plugins/validate/jquery.validate.extend.js"></script>
<script type="text/javascript">
	//回车登录
    document.onkeydown =cdk;
    function cdk(){
        if(event.keyCode ==13){
            login();
        }
    }
    $(function () {
        validateRule();
    });
    $.validator.setDefaults({
        submitHandler: function () {
            login();
        }
    });

    var countdown = 60;
    function settime(val) {
        if (countdown == 0) {
            val.removeAttribute("disabled");
            val.value = "获取验证码";
            countdown = 60;
        } else {
            val.setAttribute("disabled", true);
            val.value = "重新发送(" + countdown + ")";
            countdown--;
            var myVar = setTimeout(function () {
                settime(val)
            }, 1000)
        }
    }

    function checkMobile(sMobile) {
        if (!(/^1[3|4|5|6|7|8|9][0-9]\d{8}$/.test(sMobile))) {
            layer.msg('手机号码填写错误，请填写正确的手机格式', {
                icon: 2,
                time: 2000
            });
            document.mobileform.mobile.focus();
            return false;
        }
        return true;
    }

    function send(val) {
        var name = $("#mobile").val();
        if (name.length != 0) {
            $.ajax({
                url: '/jzApi/utils/sendPassWordCode',
                type: 'POST',
                data: {mobile: name, wxId: 103},
                success: function (data) {
                    checkMobile(name);
                    if (data == 1) {
                        val.removeAttribute("disabled");
                        val.value = "获取验证码";
                        countdown = 60;
                        layer.msg("此手机号码已注册", {icon: 0, time: 1000})
                    } else {
                        layer.msg("发送成功");
                        val.setAttribute("disabled", true);
                        val.value = "重新发送(" + countdown + ")";
                        countdown--;
                        setTimeout(function () {
                            settime(val)
                        }, 1000)
                    }
                }
            })
        } else {
            layer.msg('请输入手机号！');
        }
    }


    function login() {
		var password = $("#password").val();
		var newPassword = $("#newPassWord").val();
		if (password != newPassword){
			layer.msg("两次密码输入不一致，请修改后提交！")
		}else {
			$.ajax({
				url: "/jzApi/utils/forgetPassWord",
				data:$("#signupForm").serialize(),
				success: function (r) {
					if (r.code == 0) {
						layer.msg("修改成功");
						setTimeout(function () {
							location.href = '/certificate/loginWeb';
						}, 1000)
					} else {
						layer.msg(r.msg);
					}
				}
			})
		}
	}

	function validateRule() {
		var icon = "<i class='fa fa-times-circle'></i>";
		$("#signupForm").validate({
			rules: {
                mobile: {
					required: true,
   					 isPhone:true
				},
                code: {
					required: true
				},
                newPassWord: {
                    required: true,
                    checkPassword1:true,
					minlength:8,
					maxlength:15
                },
                password: {
                    required: true
                }
			},
			messages: {
                mobile: {
					required: icon + "请输入手机号"
				},
                code: {
					required: icon + "请输入验证码"
				},
                newPassWord: {
                    required: icon + "请输入新密码",
                    minlength:'密码最少8位',
                    maxlength:'密码最长15位'
                },
                password: {
                    required: icon + "请确认新密码"
                }
			}
		})
	}
</script>

</body>





